//Code by Daylife
#include <bits/stdc++.h>
using namespace std;

int n, a[200005];

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    scanf("%d", &t);
    while(t--){
        scanf("%d", &n);
        int T=0;
        for(int i=0; i<n; i++){
            scanf("%d", a+i);
        }

        int maxv=-1, l1, l2;
        for(int x=0; x<(1<<n); x++){
            l1=-1, l2=-1;
            int s=0;
            for(int i=0; i<n; i++){
                if((x>>i)&1){
                    if(l1==a[i]) s += a[i];
                    l1 = a[i];
                }
                else{
                    if(l2==a[i]) s += a[i];
                    l2 = a[i];
                }
            }
            maxv = max(s, maxv);
        }
        printf("%d\n", maxv);
    }
    return 0;
}
